const app = getApp();
Component({
  properties: {
    parameter: {
      type: Object,
      value: {
        class: '0'
      }
    },
    logoUrl: {
      type: String,
      value: ''
    }
  },
  data: {
    navH: ''
  },
  ready: function () {
    this.setClass();
    const pages = getCurrentPages();
    if (pages.length <= 1) {
      this.setData({'parameter.return': 0});
    }
  },
  attached: function () {
    this.setData({
      navH: app.globalData.navHeight
    });
  },
  methods: {
    return: function (e) {
      const url = e.currentTarget.dataset.url;

      if (url) {
        if (url == '/pages/index/index' || url == '/pages/my/index') {
          wx.switchTab({url: url});
          return;
        }
        wx.redirectTo({url: url});
      } else {
        // wx.navigateBack();
      }
    },
    goHome: function (e) {
      const url = e.currentTarget.dataset.url;
      if (url == '/pages/member/index') {
        wx.switchTab({url: url});
        return;
      }

      if (url) {
        wx.redirectTo({url: url});
      } else {
        let pages = getCurrentPages()
        if (pages.length > 1) {
          wx.navigateBack()
        }
      }
    },
    setClass: function () {
      let color = '';
      switch (this.data.parameter.class) {
        case '0':
        case 'on':
          color = 'on';
          break;
        case '1':
        case 'black':
          color = 'black';
          break;
        case '2':
        case 'gray':
          color = 'gray';
          break;
        case '3':
        case 'red':
          color = 'red';
          break;
        case '4':
        case 'gradual01':
          color = 'gradual01';
          break;
        default:
          break;
      }

      this.setData({
        'parameter.class': color
      });
    }
  }
});
